package com.guaika.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guaika.reggie.common.ResultMessage;
import com.guaika.reggie.common.StringChars;
import com.guaika.reggie.entity.Category;
import com.guaika.reggie.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author GuaiKa
 */
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    CategoryService categoryService;

    /***
     * 新增菜品分类
     * @param category
     * @return
     */
    @PostMapping
    public ResultMessage<String> save(@RequestBody Category category){
        categoryService.save(category);
        return ResultMessage.error(StringChars.SAVE_MESSAGE.getStr());
    }

    /***
     * 获取信息并分页
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public ResultMessage<Page> query(int page,int pageSize){
        return categoryService.categoryQuery(page, pageSize);
    }

    /***
     * 获取分类
     * @param category
     * @return
     */
    @GetMapping("/list")
    public ResultMessage<List<Category>> listCategory(Category category){
        return categoryService.listCategory(category);
    }


    /***
     * 删除分类
     * @param id
     * @return
     */
    @DeleteMapping
    public ResultMessage<String> delete(Long id){
        categoryService.remove(id);
        return ResultMessage.success(StringChars.DELETE_SUCCESS.getStr());
    }

    /***
     * 修改分类信息
     * @param category
     * @return
     */
    @PutMapping
    public ResultMessage<String> update(@RequestBody Category category){
        categoryService.updateById(category);
        return ResultMessage.success(StringChars.UPDATE_SUCCESS.getStr());
    }
}
